
package hopital.orm;

import hopital.sql.SqlQuery;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Administrateur extends Utilisateur{

    public Administrateur(String _nom, String _prenom, String _email, String _adresse, String _telephone) {
        super(_nom, _prenom, _email, _adresse, _telephone);
    }

    public Administrateur() {
    }

    
    
    public Administrateur(ResultSet _rs) throws SQLException {
        super(_rs);
    }

    @Override
    public SqlQuery insert() {
        return new SqlQuery("INSERT INTO t_admins (c_nom,c_prenom,c_email,c_adresse,c_telephone,c_password) VALUES(?,?,?,?,?,?);", _nom,_prenom,_email,_adresse,_telephone,_motDePass);
    }

    @Override
    public SqlQuery update() {
        return new SqlQuery("UPDATE t_admins SET c_nom=?,c_prenom=?,c_email=?,c_adresse=?,c_telephone=? ,c_password=? WHERE c_id=?;", _nom,_prenom,_email,_adresse,_telephone,_motDePass,_id);
    }

    @Override
    public SqlQuery delete() {
        return new SqlQuery("DELETE FROM t_admins WHERE c_id=?;", _id);
    }

    @Override
    public SqlQuery select() {
        if(_id!=-1){
            return new SqlQuery("SELECT * FROM t_admins WHERE c_id=?;", _id);
        }else{
            return new SqlQuery("SELECT * FROM t_admins;");
        }
    }

    @Override
    public List<Object> getTable(ResultSet _rs) throws Exception {
        List<Object> list=new ArrayList<>();
        while (_rs.next()) {            
            list.add(new Administrateur(_rs));
        }
        return list;
    }

}
